package models

import (
	"time"
)

type ApiLog struct {
	Id     int       `xorm:"not null pk autoincr INT(11)"`
	UserId int       `xorm:"not null comment('操作用户编号') index INT(11)"`
	Url    string    `xorm:"not null comment('请求地址') VARCHAR(1024)"`
	Param  string    `xorm:"comment('请求参数') VARCHAR(5120)"`
	Method string    `xorm:"comment('请求方法') VARCHAR(10)"`
	Result string    `xorm:"not null comment('返回参数') MEDIUMTEXT"`
	Time   time.Time `xorm:"not null created comment('请求时间') DATETIME"`
}

func (c *ApiLog) Add() bool {
	if _, err := engine.Insert(c); err != nil {
		return false
	}
	return true
}

// Insert 插入api_log表
func (m *ApiLog) Insert(signURL, method, param string, data []byte) (int64, error) {
	m.Result = string(data)
	return engine.Insert(m)
}
